package
{
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	import flash.system.Security;
	import flash.system.SecurityDomain;
	
	import org.data.model.global.GlobalModel;
	import org.interfaces.ILoader;
	import org.manager.GlobalManager;
	import org.manager.LoaderManager;
	import org.manager.ServerManager;
	import org.map.core.IsoUtil;
	import org.net.AbcLoaderText;
	import org.net.loader.ResManager;
	import org.net.loader.ResourceData;
	import org.net.loader.SwfLoader;
	import org.scene.MainScene;
	import org.ui.ImageButton;
	
	[SWF(width=1024, height=768, frameRate=30,backgroundColor="#321519")]
	public class Main extends MovieClip
	{
		private var icon:Loader
		var mainScene:MainScene = new MainScene();
		
		public function Main()
		{
			trace("bbb");
			this.addEventListener(Event.ADDED_TO_STAGE,loadID);
		}
		
		/**
		 * 1001:加载初始化 
		 * 1002:加载字典文件结束
		 * 1003:加载结束
		 * @param e
		 * 
		 */		
		private function loadID(e:Event):void{
			LoaderManager.instance.registerLoadHandler(AbcLoaderText,"../asset/id.txt",initialize)
		}
		
		var loader:Loader = new  Loader();
		var domain:ApplicationDomain = ApplicationDomain.currentDomain;
		private function initialize(e:ILoader):void{
			//当前用户赋值
			GlobalModel.userId = e.data;
			trace("userId:" + GlobalModel.userId);
			//全局变量
			//GlobalManager.instance.initialize(stage);
			
			stage.addChild(mainScene);
			ResManager.instance.add(new SwfLoader(new ResourceData("http://xnimg.cn/xnapp/youqu/tiny_battle//flash/1206192132/asset/swf/mapItem/pet.swf")));
			ResManager.instance.add(new SwfLoader(new ResourceData("http://xnimg.cn/xnapp/youqu/tiny_battle//flash/1206192132/asset/swf/TIP.swf","aa1")));
			ResManager.instance.add(new SwfLoader(new ResourceData("http://xnimg.cn/xnapp/youqu/tiny_battle//flash/1206192132/asset/swf/mapItem/building.swf","aa2")));
			ResManager.instance.add(new SwfLoader(new ResourceData("http://xnimg.cn/xnapp/youqu/tiny_battle//flash/1206192132/asset/swf/Actordress/actor.swf","aa3")));
			ResManager.instance.add(new SwfLoader(new ResourceData("http://xnimg.cn/xnapp/youqu/tiny_battle//flash/1206192132/asset/swf/mapItem/seed.swf","aa4")));
//			ResManager.instance.add(new SwfLoader(new ResourceData("../asset/swf/TIP.swf","tip")));
//			ResManager.instance.add(new SwfLoader(new ResourceData("../asset/swf/loading_init.swf","load_init")));
//			ResManager.instance.add(new SwfLoader(new ResourceData("../asset/swf/ColorFont.swf","a")));
//			ResManager.instance.add(new SwfLoader(new ResourceData("../asset/swf/cursor.swf")));
//			ResManager.instance.add(new SwfLoader(new ResourceData("../asset/swf/effect.swf")));
//			ResManager.instance.add(new SwfLoader(new ResourceData("../asset/swf/expDropIcon.swf")));
//			ResManager.instance.add(new SwfLoader(new ResourceData("../asset/swf/mapbg.swf")));
			ResManager.instance.addEventListener(Event.COMPLETE, completeHandler);
			ResManager.instance.load();
			
			IsoUtil.createMap(mainScene);
			
//			var child:Shape = new Shape();
//			child.graphics.beginFill(0xFFCC00);
//			child.graphics.lineStyle(10, 0xFFCC00);
//			child.graphics.drawRoundRect(0, 0, 100, 100, 10);
//			child.graphics.endFill();
//			mainScene.addChild(child);
			/*
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadingInitComplete); 
			var context : LoaderContext = new LoaderContext();
			context.applicationDomain = domain
			loader.load(new URLRequest("../asset/swf/TIP.swf"),context);
			
			
			var img:BitmapData = new BitmapData(100,100);
			var btn:ImageButton = ImageButton.createImageButtonScaleBitmap(img,1.0);
			//mainScene.addChild(btn);
			//ServerManager.instance.callServer(["getUserInfo", [], ["test"]]);
			*/
		}
		
		private function completeHandler(event : Event) : void {
//			var btn_ok_DB:MovieClip = ResManager.instance.getMovieClip("tip", "HtmlText_TIP_view")
//			var mc:MovieClip = ResManager.instance.getMovieClip("load_init", "loading_init")
			
//			mainScene.addChild(btn_ok_DB);
//			mainScene.addChild(mc);
		}
		
		/**
		 *	初始化完成监听
		 */		
		private function loadingInitComplete(event:Event):void{
			var child:Class = domain.getDefinition("HtmlText_TIP_view") as Class;
			var btn_ok_DB:MovieClip = new child() as MovieClip
			//mainScene.addChild(btn);
			mainScene.addChild(btn_ok_DB);
		}
		
	}
}